<?php
include_once 'dbcofig.php';
if (isset ( $_REQUEST ['username'] )) {
	$username = trim ( $_REQUEST ['username'] );
	$password = trim ( $_REQUEST ['password'] );
	$password1 = trim ( $_REQUEST ['password1'] );
	if ($username == '' || $password == '') {
		echo "用户名或者密码不能为空<a href='registeration.php'>重试</a>";
		exit ();
	}
	if ($password != $password1) {
		echo "两次密码不一致<a href='registeration.php'>重试</a>";
		exit ();
	}
	$password = sha1 ( $password );
	$statement = "insert into user(username,password) values(:username,:password)";
	$s = $pdo->prepare ( $statement );
	$res = $s->execute ( array (
			"username" => $username,
			"password" => $password
	) );
	if ($res) {
		$lines = $s->rowCount ();
		if ($lines > 0) {
			echo "数据库保存成功<a href='login.php'>返回登录页面</a>";
			exit ();
		} else {
			echo "数据保存失败<a href='registeration.php'>重试</a>";
		}
	} else {
		echo "数据内部错误<a href='registeration.php'>重试</a>";
	}
} else {
	header("location:jump.php?error=登录失败&url=registeration.php&wait=3");
}